#!/bin/bash

last_tag=`git describe --tags|cut -d- -f1`

if [ ! -z "$1" ]
then
  last_tag=$1
fi

version=$(jq -r .version package.json)

token=$(git config --global github.token)

echo "# $version ($(date +%F))"
for pr in $(git log --reverse --grep "Merge pull request" "$last_tag"..HEAD | sed -nEe 's/.*#([0-9]+).*/\1/p'); do
    title=$(curl -s https://$token@api.github.com/repos/serverless/serverless/pulls/$pr | jq -r .title)
    echo " - [$title](https://github.com/serverless/serverless/pull/$pr)"
done
echo
echo "## Meta"
echo " - [Comparison since last release](https://github.com/serverless/serverless/compare/$last_tag...v$version)"
echo
echo
